package com.cytech.cloudclinic.adapter;

import android.content.Context;
import android.widget.LinearLayout;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.bean.Drug;
import com.cytech.cloudclinic.utils.ConvertUtils;

import java.util.List;

import static com.cytech.cloudclinic.app.Constant.DRUG_TAG_6;

public class DrugAdapter extends BaseQuickAdapter<Drug, BaseViewHolder> {

    private int parentDrugTagId;

    public DrugAdapter(List<Drug> data,int parentDrugTagId) {
        super(R.layout.item_drug, data);
        this.parentDrugTagId = parentDrugTagId;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Drug drug) {
        baseViewHolder.setText(R.id.item_drug_name,drug.drug_name);
        if(parentDrugTagId == DRUG_TAG_6){
            baseViewHolder.setText(R.id.item_drug_size,String.format("%d%s/%s",drug.number,drug.subunit,drug.parent_unit));
            baseViewHolder.setText(R.id.item_drug_price,String.format("%s元/%s元", ConvertUtils.m2(drug.sub_price),ConvertUtils.m2(drug.parent_price)));
        }else{
            baseViewHolder.setText(R.id.item_drug_size,String.format("%d%s",drug.number,drug.subunit));
            baseViewHolder.setText(R.id.item_drug_price,String.format("%s元", ConvertUtils.m2(drug.sub_price)));
        }
        baseViewHolder.setText(R.id.item_drug_factory,drug.company);

        LinearLayout bg = baseViewHolder.getView(R.id.item_drug_container);
        if(baseViewHolder.getLayoutPosition()%2==0){
            bg.setBackgroundColor(ContextCompat.getColor(getContext(),R.color.white));
        }else{
            bg.setBackgroundColor(ContextCompat.getColor(getContext(),R.color.color_f3f8ff));
        }
    }
}
